#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>
#define N 11
int main()
{
	int i, DA, DB, PA = 0, PB = 0;
	char A[N], B[N];
	scanf("%s%d%s%d", A, &DA, B, &DB);
	for (i = 0; i < N; i++)
	{
		if ((A[i] - 48) == DA)
			PA = PA * 10 + DA;
		if ((B[i] - 48) == DB)
			PB = PB * 10 + DB;
	}
	printf("%d", PA + PB);
	return 0;
}
